<?php
namespace App\Http\Forms;

use App\Library\OSS;
use Kris\LaravelFormBuilder\Form;

class PackageForm extends Form
{
    public function buildForm()
    {
        $key = "video"."/".uniqid().random_int(10, 99);
        foreach (config('system.package_category') as $value) {
            $category[$value] = $value;
        }
        $this
//            ->add('shop_id', 'select', [
//                'label' => "店铺",
//                'rules' => 'required|string',
//                'choices' => $this->getData('shop'),
//            ])
//            ->add('category', 'select', [
//                'label' => "类别",
//                'rules' => 'required|string',
//                'choices' => $category,
//            ])
            ->add('name', 'text', [
                'label' => "套系名称",
                'rules' => 'required|string',
            ])

            ->add('display_price', 'text', [
                'label' => "划线价",
                'rules' => 'required|numeric',
            ])
            ->add('price', 'text', [
                'label' => "价格",
                'rules' => "required|numeric",
            ])
            ->add('prepay', 'text', [
                'label' => '预付金额',
                'rules' => "required|integer",
                'default_value' => 0,
            ])
            ->add('virtual_sales_volume', 'text', [
                'label' => "虚拟销量",
                'rules' => "nullable|integer",
            ])
            ->add('sort', 'text', [
                'label' => '排序权重',
                'rules' => 'required|integer',
                'default_value' => 0,
            ])

            ->add('photo', 'text', [
                'label' => "拍摄",
                'rules' => "required|integer",
                'default_value' => 0,
            ])
            ->add('modelling', 'text', [
                'label' => "造型",
                'rules' => "required|integer",
                'default_value' => 0,
            ])
            ->add('truing', 'text', [
                'label' => "精修",
                'rules' => "required|integer",
                'default_value' => 0,
            ])

            ->add('is_free', 'checkbox', [
                'label' => "是否参与免费购",
                'rules' => "nullable|integer",
            ])
            ->add('is_balance_pay', 'checkbox', [
                'label' => "是否可以使用充值消费",
                'rules' => "nullable|integer",
            ])
            ->add('is_recharge', 'checkbox', [
                'attr' => ['id' => "is_recharge"],
                'label' => "本商品是否为充值商品",
                'rules' => "nullable|integer",
            ])
            ->add('recharge_money', 'text', [
                'attr' => ['id' => "recharge_money"],
                'label' => "实际充值金额",
                'rules' => 'numeric',
            ])
            ->add('end_time', 'text', [
               'label' => "活动结束时间",
               'rules' => "nullable|date",
            ])

            ->add('tag_id', 'select', [
                'attr' => ['class' => "form-control select2", 'multiple' => "multiple", 'id' => "tag_id-select"],
                'label' => "服务标签",
                'rules' => '',
                'choices' => $this->getData('tag_id') ?? [],
                'empty_value' => ['无'],
            ])

            ->add('cover', 'image_list', [
                'label' => "展示图",
                'rules' => 'required|array',
                'type' => 'package_cover',
                'help_block' => [
                    'text' => "建议尺寸600*600",
                ]
            ])
            ->add('video', 'video', [
                'label' => "上传视频",
                'rules' => 'nullable',
                'async' => true,
                'config' => OSS::instance('video')->getSign($key),
            ])
            ->add('order_cover', 'image', [
                'label' => "订单展示图",
                'rules' => 'required|string',
                'type' => 'order_cover',
                'help_block' => [
                    'text' => "建议尺寸150*150",
                ]
            ])
            ->add('hot_cover', 'image', [
                'label' => "套系封面图",
                'rules' => 'required|string',
                'type' => 'hot_cover',
                'help_block' => [
                    'text' => "建议尺寸332*332",
                ]
            ])
            ->add('recommend_cover', 'image', [
                'label' => "推荐套系封面图",
                'rules' => 'required|string',
                'type' => 'recommend_cover',
                'help_block' => [
                    'text' => "建议尺寸334*192",
                ]
            ])
            ->add('selected_cover', 'image', [
                'label' => "精选套系封面图",
                'rules' => 'required|string',
                'type' => 'selected_cover',
                'help_block' => [
                    'text' => "建议尺寸682*240",
                ]
            ])
            // ->add('share_bg', 'image', [
            //     'label' => "海报背景图",
            //     'rules' => 'required|string',
            //     'type' => 'share',
            //     'help_block' => [
            //         'text' => "建议尺寸632*1068",
            //     ]
            // ])
            
//            ->add('discount_limit', 'text', [
//                'label' => "满减限额",
//                'rules' => "nullable|integer",
//            ])
//            ->add('discount_amount', 'text', [
//                'label' => "满减额",
//                'rules' => "nullable|integer",
//            ])
            
            ->add('description', 'textarea', [
                'attr' => ['id' => 'editor'],
                'label' => "介绍",
                'rules' => 'required|string',
            ])
            ->add('service', 'include', [
                'label' => "产品和服务",
                'rules' => "required",
                'path' => "package.package_service_form",
                'package_attr' => $this->getData('package_attr'),
                'package_value' => $this->getData('package_value'),
            ])
            
//            ->add('spec', 'include', [
//                'label' => "可选择的产品",
//                'rules' => "required",
//                'path' => "package.package_spec_form",
//                'package_attr' => $this->getData('package_attr'),
//                'package_value' => $this->getData('package_value'),
//            ])
            ->add('submit', 'submit', [
                'attr' => ['class' => "form-control btn btn-success"],
                'label' => '保存',
            ]);
    }
}
